<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>姓名案例-计算属性实现</title>
    <script src="../commonjs/vue.js"></script>
</head>
<body>
    <div id="root">
        姓:<input type="text" v-model="person.firstName"><br><br>
        名:<input type="text" v-model="person.lastName"><br><br>
        全名:<span>{{fullName}}</span>
    </div>
    <script>
        Vue.config.productionTip = false;//关闭开发提示
        let vm = new Vue({
            el:'#root',
            data:{
                school:{name:'武威职业学院'},
                person:{
                    firstName:'',
                    lastName:''
                }
            },
            computed:{
                fullName:{
                    get(){
                        console.log("get()")
                        return this.person.firstName+"-"+this.person.lastName
                    },
                    set(value){
                        console.log("set()")
                        const arr = value.split("-")
                        this.person.firstName = arr[0]
                        this.person.lastName = arr[1]
                    }
                }
            }
        })
    </script>
</body>
</html>